package com.javasea.qrprint;

import com.javasea.qrprint.controller.RootController;
import com.javasea.qrprint.controller.SampleController;
import com.javasea.qrprint.util.UiUtil;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

import java.io.IOException;

public class Main extends Application {

    private static RootController rootPaneController;

    @Override
    public void start(Stage primaryStage) throws Exception{
        FXMLLoader rootLoader = new FXMLLoader(getClass().getClassLoader().getResource("fxml/RootController1.fxml"));
        Pane rootPane = rootLoader.load();

        // 获取主界面控制器
        RootController rootPaneController = rootLoader.getController();
        Main.rootPaneController = rootPaneController;

        primaryStage.setScene(new Scene(rootPane));
        primaryStage.setTitle("公司简介");
        primaryStage.show();

        // 加载子fxml
        loadChildFXML();

        /** 初始化UI提示 */
        UiUtil.scheduleInit(primaryStage);
        UiUtil.popupStartupConfirm(primaryStage);

        // 添加子pane
        rootPaneController.setChildPaneController();
        /** 截图 */
        rootPaneController.takeSnapShot();

    }

    /**
     * 加载各子界面即模板UI
     */
    private void loadChildFXML() {
        try {
            FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource("fxml/SampleController.fxml"));
            Pane pane = loader.load();
            SampleController controller = loader.getController();
            // 添加到主界面控制器中
            rootPaneController.addChildPane(controller);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}
